<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new deque using a callable to
    determine which values to include</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-deque.count.html">« Ds\Deque::count</a></li>
      <li style="float: right;"><a href="ds-deque.find.html">Ds\Deque::find »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.ds-deque.html">Deque</a></li>
    <li>Creates a new deque using a callable to
    determine which values to include</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ds-deque.filter" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Ds\Deque::filter</h1>
  <p class="verinfo">(PECL ds &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Deque::filter</span> &mdash; <span class="dc-title">
    Creates a new deque using a <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> to
    determine which values to include
 </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-ds-deque.filter-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>Ds\Deque::filter</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-deque.html" class="type Ds\Deque">Ds\Deque</a></span></div>

  <p class="para rdfs-comment">
    Creates a new deque using a <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> to
    determine which values to include.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-ds-deque.filter-parameters">
  <h3 class="title">参数</h3>
 <dl>

    
    <dt>
<code class="parameter">callback</code></dt>


    <dd>

        <p class="para">
            <div class="methodsynopsis dc-description"><span class="methodname"><span class="replaceable">callback</span></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>

        </p>
        <p class="para">
            Optional <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> which returns <strong><code>true</code></strong> if the value should be included, <strong><code>false</code></strong> otherwise.
        </p>
        <p class="para">
            If a callback is not provided, only values which are <strong><code>true</code></strong>
            (see <a href="language.types.boolean.html#language.types.boolean.casting" class="link">converting to boolean</a>)
            will be included.
        </p>
    </dd>


   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-ds-deque.filter-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    A new deque containing all the values for which
    either the <code class="parameter">callback</code> returned <strong><code>true</code></strong>, or all values that
    convert to <strong><code>true</code></strong> if a <code class="parameter">callback</code> was not provided.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-ds-deque.filter-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4040">
   <p><strong>示例 #1 <span class="function"><strong>Ds\Deque::filter()</strong></span> example using callback function</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$deque&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Deque</span><span style="color: #007700">([</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$deque</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">filter</span><span style="color: #007700">(function(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">%&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />}));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(Ds\Deque)#3 (2) {
  [0]=&gt;
  int(2)
  [1]=&gt;
  int(4)
}
</pre></div>
   </div>
  </div>
  <div class="example" id="example-4041">
   <p><strong>示例 #2 <span class="function"><strong>Ds\Deque::filter()</strong></span> example without a callback function</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$deque&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Deque</span><span style="color: #007700">([</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$deque</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">filter</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(Ds\Deque)#2 (3) {
  [0]=&gt;
  int(1)
  [1]=&gt;
  string(1) &quot;a&quot;
  [2]=&gt;
  bool(true)
}
</pre></div>
   </div>
  </div>
 </div>



</div></div></div></body></html>